package xj.graph2d.app;

import xj.graph2d.Document;
import xj.graph2d.GraphDocument;
import xj.graph2d.GraphView;

public class GraphAppView extends GraphView {

  public GraphAppView(DrawApp main, GraphDocument gdoc) {
    super(gdoc, main.drawattr, main.headArrowAttr, main.tailArrowAttr);
    this.gdoc = gdoc;
    this.main = main;
    scrollcanvas.setShowMargin(true);
  }

  @Override
  protected void initView() {
    if (GraphApp.debug) {
      System.out.println("GraphAppView.initView()");
    }

  }

  @Override
  public void displayLocation(float x, float y) {
    if (main != null) {
      int unit = sdoc.getUnit();
      switch (unit) {
      case Document.UNIT_INCH:
	main.displayLocation(x / Document.POINTS_PER_INCH, y / Document.POINTS_PER_INCH);
	break;
      case Document.UNIT_CM:
	main.displayLocation(x / Document.POINTS_PER_CM, y / Document.POINTS_PER_CM);
	break;
      case Document.UNIT_PIXEL:
      default:
	main.displayLocation((int) x, (int) y);
	break;
      }
    }
  }

  @Override
  public void displayLocation(int x, int y) {
    if (main != null) {
      main.displayLocation(x, y);
    }
  }

  @Override
  public void displayMessage(String text) {
    if (main != null) {
      main.displayMessage(text);
    }
  }

  @Override
  public void displayHelpMessage(String key) {
    if (main != null) {
      main.displayHelpMessage(key);
    }
  }

  @Override
  public void startBusyMessage(String key) {
    if (main != null) {
      main.hourGlassOn();
      if (key != null) { 
	main.displayHelpMessage(key);
      }
    }
  }

  @Override
  public void endBusyMessage(String key) {
    if (main != null) {
      main.hourGlassOff();
      if (key != null) { 
	main.displayHelpMessage(key);
      }
    }
  }

  public DrawApp getMain() { 
    return main;
  }

  protected GraphDocument gdoc;

  protected DrawApp main;

}
